package com.ruoyi.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.ServletUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Cate;
import com.ruoyi.system.service.ICateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行业类目Controller
 *
 * @author ruoyi
 * @date 2024-08-30
 */
@RestController
@RequestMapping("/system/cate")
public class CateController extends BaseController {
    @Resource
    private ICateService cateService;

    /**
     * 查询行业类目列表
     */
    //@PreAuthorize("@ss.hasPermi('system:cate:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cate cate) {
        if (Convert.toInt(ServletUtils.getParameter("pageNum")) != -1
                && Convert.toInt(ServletUtils.getParameter("pageSize")) != -1) {
            startPage();
        }
        List<Cate> list = cateService.selectCateList(cate);
        return getDataTable(list);
    }

    /**
     * 查询行业类目列表
     */
    @GetMapping("/list_anonymous")
    @Anonymous
    public TableDataInfo list_anonymous(Cate cate) {
        if (Convert.toInt(ServletUtils.getParameter("pageNum")) != -1
                && Convert.toInt(ServletUtils.getParameter("pageSize")) != -1) {
            startPage();
        }
        List<Cate> list = cateService.selectCateList(cate);
        return getDataTable(list);
    }

    /**
     * 导出行业类目列表
     */
    //@PreAuthorize("@ss.hasPermi('system:cate:export')")
    @Log(title = "行业类目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cate cate) {
        List<Cate> list = cateService.selectCateList(cate);
        ExcelUtil<Cate> util = new ExcelUtil<Cate>(Cate.class);
        util.exportExcel(response, list, "行业类目数据");
    }

    /**
     * 获取行业类目详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:cate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cateService.selectCateById(id));
    }

    /**
     * 新增行业类目
     */
    //@PreAuthorize("@ss.hasPermi('system:cate:add')")
    @Log(title = "行业类目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cate cate) {
        return toAjax(cateService.insertCate(cate));
    }

    /**
     * 修改行业类目
     */
    //@PreAuthorize("@ss.hasPermi('system:cate:edit')")
    @Log(title = "行业类目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cate cate) {
        return toAjax(cateService.updateCate(cate));
    }

    /**
     * 删除行业类目
     */
    //@PreAuthorize("@ss.hasPermi('system:cate:remove')")
    @Log(title = "行业类目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cateService.deleteCateByIds(ids));
    }
}
